package com.csu.service.impl;

import com.csu.common.CommonResponse;
import com.csu.domain.Item;
import com.csu.persistence.ItemDao;
import com.csu.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("itemService")
public class ItemServiceImpl implements ItemService {

    @Autowired
    ItemDao itemDao;
    @Override
    public CommonResponse<List<Item>> getAllItem() {
        List<Item> itemList = itemDao.selectAllItem();
        return CommonResponse.createForSuccess(200,"SUCCESS",itemList);
    }

    @Override
    public CommonResponse<Item> getItemByItemId(String itemId) {
        Item item = itemDao.selectItemByItemId(itemId);
        return CommonResponse.createForSuccess(200,"SUCCESS",item);
    }

    @Override
    public CommonResponse<List<Item>> updateItem(Item item) {
        itemDao.editItem(item);
        return CommonResponse.createForSuccess();
    }

    @Override
    public CommonResponse<Item> addNewItem(Item item) {
        itemDao.insertNewItem(item);
        return CommonResponse.createForSuccess();
    }

    @Override
    public CommonResponse<Object> deleteItemByItemId(String itemId) {
        itemDao.deleteItemByitemId(itemId);
        return CommonResponse.createForSuccess();
    }
}
